package com.app.xinfadi.widget.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.TextView;

import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.widget.base.BaseDialog;
import com.app.xinfadi.R;


/**
 * Function:
 * <br/>
 * Create on:2015/10/22 18:33
 * <br/>
 * Author:WuTengFei
 */
public class VersionUpdateDialog extends BaseDialog<VersionUpdateDialog> {
    private String content;
    protected DisplayMetrics dm;
    /**
     * left btn click listener(左按钮接口)
     */
    protected OnBtnClickL onBtnLeftClickL;
    /**
     * right btn click listener(右按钮接口)
     */
    protected OnBtnClickL onBtnRightClickL;
    /**
     * max height(最大高度)
     */
    private String leftBtnText;
    private String rightBtnText;
    private String title;

    private View contentView;
    private TextView leftBtn;
    private TextView titleTv;
    private TextView rightBtn;
    private TextView contentTv;

    public VersionUpdateDialog(Context context) {
        super(context);
    }


    @Override
    public View onCreateView() {
        contentView = View.inflate(mContext, R.layout.update_version, null);
        leftBtn = (TextView) contentView.findViewById(R.id.noUpdateBtn);
        rightBtn = (TextView) contentView.findViewById(R.id.updateBtn);
        contentTv = (TextView) contentView.findViewById(R.id.contentTv);
        titleTv = (TextView) contentView.findViewById(R.id.title);
        return contentView;
    }

    @Override
    public void setUiBeforShow() {
        titleTv.setText(TextUtils.isEmpty(title) ? "升级提示" : title);
        contentTv.setLineSpacing(0, 1.3f);
        contentTv.setText(content);
        if (TextUtils.isEmpty(leftBtnText))
            leftBtn.setText(leftBtnText);
        if (TextUtils.isEmpty(rightBtnText))
            rightBtn.setText(rightBtnText);
        leftBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onBtnLeftClickL != null) {
                    onBtnLeftClickL.onBtnClick();
                }
            }
        });

        rightBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onBtnRightClickL != null)
                    onBtnRightClickL.onBtnClick();
            }
        });
        setCanceledOnTouchOutside(false);
    }


    public VersionUpdateDialog setContent(String content) {
        this.content = content;
        return this;
    }

    public VersionUpdateDialog setOnBtnClick(OnBtnClickL onBtnLeftClickL, OnBtnClickL onBtnRightClickL) {
        this.onBtnLeftClickL = onBtnLeftClickL;
        this.onBtnRightClickL = onBtnRightClickL;
        return this;
    }

    public VersionUpdateDialog setTitle(String title) {
        this.title = title;
        return this;
    }

    public VersionUpdateDialog btnText(String leftBtnText, String rightBtnText) {
        this.leftBtnText = leftBtnText;
        this.rightBtnText = rightBtnText;
        return this;
    }
}
